package com.hbnu.list;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class IteratorDemo {
    public static void main(String[] args) {
        List<String> names = new ArrayList<>();

        names.add("John");
        names.add("Wick");
        names.add("moon");
        names.add("element");

        Iterator<String> iterator = names.iterator();
        while (iterator.hasNext()) {
            String element = iterator.next();
            if ("element".equals(element)) {
                iterator.remove();
            }
            System.out.println(iterator.toString());
        }
    }
}
